package hk.controller;

import hk.beans.Payment;
import hk.common.R;
import hk.enums.EnumStatus;
import hk.service.PaymentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author YangJiaQuan_hrbnu
 * @Date 2024/3/12 23:28
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Resource
    PaymentService paymentService;

    @Value("${server.port}")
    private int port;

    @PostMapping("/addpayment")
    public R<?> addPayment(@RequestBody Payment payment) {
        paymentService.addPayment(payment);
        return new  R<>( EnumStatus.OK.getValue()  ,EnumStatus.OK.getMsg(),null);
    }

    @GetMapping("/getpayment/{id}")
    public R<Payment> get(@PathVariable("id") Integer id) {
        Payment payment=paymentService.getPaymentById(id);
        if(payment!=null){
            return new R<>(EnumStatus.OK.getValue(),EnumStatus.OK.getMsg()+"当前服务器："+port,payment);
        }else{
            return new R<>(EnumStatus.NOT_FOUND.getValue(), EnumStatus.NOT_FOUND.getMsg()+"当前服务器："+port, null);
        }
    }
}